let app = getApp();


//内网穿透工具介绍:
// https://open-doc.dingtalk.com/microapp/debug/ucof2g
//替换成开发者后台设置的安全域名
let domain = "http://127.0.0.1:8080";
let url = domain + '/DDlogin';
let urlUser = domain + '/DingDUser';


Page({
    data:{//初始化，可以初始化赋值
        corpId: '',
        authCode:'',
        userId:'',
        userName:'',
        putUser:'',
        putPassword:'',
        userInfo:'', //账号密码信息
        adminInfo:'',//职位信息
        userPassword:'',//账号密码是否正确
        hideList: true,
    },
        pre(){
      this.setData({
        name:'可莉'
      })
    },
    primary(){
      dd.vibrateShort({
      success: () => {
        dd.alert({ title: '短振动'});
      }
    });
},
    //账号密码与后端交互
  onSubmit(e) {
    dd.alert({
      content: `数据：${JSON.stringify(e.detail.value)}`,
    });
    //dd.alert({content: "step1"});\
    dd.showLoading();
    dd.httpRequest({
        url: urlUser,
        method: 'POST',
        data: {
            // authCode: res.authCode
            //向后端的请求参数
            putUser: e.detail.value.put_user,
            putPassword: e.detail.value.put_password
          
        },
        dataType: 'json',
        success: (res) => {//调用成功的回调函数。
            // dd.alert({content: "step2"});
            // console.log('success----',res)
            // let userInfo = res.data.result.data;
            // this.setData({
            //     userInfo: userInfo
            // })
            let userInfo = res.data.result.resultString;
            let adminInfo = res.data.result.adminInfo;
            let userPassword = res.data.result.userPassword;
           this.setData({
             userInfo:userInfo,
             adminInfo:adminInfo,
             userPassword:userPassword
           })
            
        },
        
        fail: (res) => {//调用失败的回调函数。
            console.log("httpRequestFail---",res)
            
            dd.alert({content: JSON.stringify(res)});
          
        },
        complete: (res) => {//调用结束的回调函数（调用成功、失败都会执行）。
            dd.hideLoading();
        }
        
    });

fail: (err)=>{
    // dd.alert({content: "step3"});
    dd.alert({
        content: JSON.stringify(err)
    })
}
        

//账号密码与后端交互
  },
    loginSystem() {
        dd.showLoading();
        dd.getAuthCode({
            success:(res)=>{
                this.setData({
                    authCode:res.authCode
                })
                //dd.alert({content: "step1"});
                dd.httpRequest({
                    url: url,
                    method: 'POST',
                    data: {
                        authCode: res.authCode
                    },
                    dataType: 'json',
                    success: (res) => {
                        // dd.alert({content: "step2"});
                        console.log('success----',res)
                        let userId = res.data.result.userId;
                        let userName = res.data.result.userName;
                        this.setData({
                            userId:userId,
                            userName:userName,
                            hideList:false
                        })
                    },
                    fail: (res) => {
                        console.log("httpRequestFail---",res)
                       dd.alert({content: JSON.stringify(res)});
                    },
                    complete: (res) => {
                        dd.hideLoading();
                    }
                    
                });
            },
            fail: (err)=>{
                // dd.alert({content: "step3"});
                dd.alert({
                    content: JSON.stringify(err)
                })
            }
        })

    },
    onLoad(){

        let _this = this;

        this.setData({
            corpId: app.globalData.corpId
        })
        
        //dd.alert({content: "step1"});
         
        
        
    }
})